//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.ScientificWorkflow.TridentUtilities
{
    #region Using Directives
    using System;
    using System.Windows;
    using System.Threading;
    #endregion

    /// <summary>
    /// Programing Logis for TridentMessageBox
    /// </summary>
    public static class TridentMessageBox
    {
        /// <summary>
        /// Message header string.
        /// </summary>
        private static string MSGHEADER = "Scientific WorkFlow";

        /// <summary>
        /// Shows the Message Box
        /// </summary>
        /// <param name="messageBoxText">string</param>
        public static void ShowTridentMessageBox(string messageBoxText)
        {
            if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
            {
                TridentMsgBox messageBox = new TridentMsgBox();
                messageBox.ShowMessage(messageBoxText, MSGHEADER);
            }
            else
            {
                MessageBox.Show(messageBoxText, MSGHEADER);
            }
        }

        /// <summary>
        ///  Shows the Message Box
        /// </summary>
        /// <param name="owner">Window</param>
        /// <param name="messageBoxText">string</param>
        public static void ShowTridentMessageBox(Window owner, string messageBoxText)
        {
            if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
            {
                TridentMsgBox messageBox = new TridentMsgBox();
                messageBox.ShowMessage(owner, messageBoxText, MSGHEADER);
            }
            else
            {
                MessageBox.Show(owner, messageBoxText, MSGHEADER);
            }
        }

        /// <summary>
        ///  Shows the Message Box with Error Icon
        /// </summary>
        /// <param name="owner">Window</param>
        /// <param name="messageBoxText">string</param>
        public static void ShowTridentErrorMessageBox(Window owner, string messageBoxText)
        {
            if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
            {
                TridentMsgBox messageBox = new TridentMsgBox();
                messageBox.ShowMessage(owner, messageBoxText, MSGHEADER, MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                MessageBox.Show(owner, messageBoxText, MSGHEADER, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        /// <summary>
        ///  Shows the Message Box with Error Icon
        /// </summary>
        /// <param name="messageBoxText">string</param>
        public static void ShowTridentErrorMessageBox(string messageBoxText)
        {
            if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
            {
                TridentMsgBox messageBox = new TridentMsgBox();
                messageBox.ShowMessage(messageBoxText, MSGHEADER, MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                MessageBox.Show(messageBoxText, MSGHEADER, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        /// <summary>
        ///  Shows the Message Box with Warning Icon
        /// </summary>
        /// <param name="owner">Window</param>
        /// <param name="messageBoxText">string</param>
        public static void ShowTridentWarningMessageBox(Window owner, string messageBoxText)
        {
            if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
            {
                TridentMsgBox messageBox = new TridentMsgBox();
                messageBox.ShowMessage(owner, messageBoxText, MSGHEADER, MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else
            {
                MessageBox.Show(owner, messageBoxText, MSGHEADER, MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }

        /// <summary>
        ///  Shows the Message Box Information ICON.
        /// </summary>
        /// <param name="messageBoxText">string</param>
        public static void ShowTridentInformationMessageBox(Window owner, string messageBoxText)
        {
            if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
            {
                TridentMsgBox messageBox = new TridentMsgBox();
                messageBox.ShowMessage(owner, messageBoxText, MSGHEADER, MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                MessageBox.Show(owner, messageBoxText, MSGHEADER, MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }

        /// <summary>
        ///  Shows the Message Box with Warning Icon
        /// </summary>
        /// <param name="messageBoxText">string</param>
        public static void ShowTridentWarningMessageBox(string messageBoxText)
        {
            if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
            {
                TridentMsgBox messageBox = new TridentMsgBox();
                messageBox.ShowMessage(messageBoxText, MSGHEADER, MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else
            {
                MessageBox.Show(messageBoxText, MSGHEADER, MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }

        /// <summary>
        ///  Shows the Message Box with  Yes No Cancel Buttons
        /// </summary>
        /// <param name="messageBoxText">string</param>
        public static MessageBoxResult ShowTridentConfirmationYesNoCancelMessageBox(string messageBoxText)
        {
            MessageBoxResult result;
            if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
            {
                TridentMsgBox messageBox = new TridentMsgBox();
                result =
                    messageBox.ShowMessage(messageBoxText, MSGHEADER, MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.Yes);
            }
            else
            {
                result =
                    MessageBox.Show(messageBoxText, MSGHEADER, MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.Yes);
            }

            return result;
        }

        /// <summary>
        ///  Shows the Message Box with  Yes No Buttons
        /// </summary>
        /// <param name="messageBoxText">string</param>
        public static MessageBoxResult ShowTridentConfirmationYesNoMessageBox(string messageBoxText)
        {
            MessageBoxResult result;
            if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
            {
                TridentMsgBox messageBox = new TridentMsgBox();
                result =
                    messageBox.ShowMessage(messageBoxText, MSGHEADER, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes);
            }
            else
            {
                result =
                    MessageBox.Show(messageBoxText, MSGHEADER, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes);
            }
            return result;
        }

        /// <summary>
        ///  Shows the Message Box Information ICON.
        /// </summary>
        /// <param name="messageBoxText">string</param>
        public static void ShowTridentInformationMessageBox(string messageBoxText)
        {
            if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
            {
                TridentMsgBox messageBox = new TridentMsgBox();
                messageBox.ShowMessage(messageBoxText, MSGHEADER, MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                MessageBox.Show(messageBoxText, MSGHEADER, MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }

        /// <summary>
        /// Shows the Message box with Ok and Cancel button
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static MessageBoxResult ShowTridentConfirmationOkCancelMessageBox(string message)
        {
            MessageBoxResult result;
            if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
            {
                TridentMsgBox messageBox = new TridentMsgBox();
                result =
                    messageBox.ShowMessage(message, MSGHEADER, MessageBoxButton.OKCancel, MessageBoxImage.Information, MessageBoxResult.OK);
            }
            else
            {
                result =
                    MessageBox.Show(message, MSGHEADER, MessageBoxButton.OKCancel, MessageBoxImage.Information, MessageBoxResult.OK);
            }

            return result;
        }
    }
}
